package com.demo.spark.stream;


import java.io.IOException;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class StreamSocketServer {
    public static void main(String[] args) {
        /*
        开启一个tcp server，当接收到连接请求时，不间断的向该请求传回数据
         */
        ServerSocket socketServer = null;
        Socket socket = null;
        try {
            socketServer = new ServerSocket(9999);
            socket = socketServer.accept();
            OutputStream outputStream = socket.getOutputStream();
            while (true){
                outputStream.write("a b c d \n".getBytes());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                socket.close();
                socketServer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }
}
